
<?php echo($javascript->link("countdown.js"));  ?>

<div class="sales index">
<ul class="items">
<?php
$i = 0;
foreach ($follows as $follow):
?>
	
	<li>
		<table class="itemsTable">
			<tr>
				<td>
				
				<?php 	
							$photo = $follow['Sale']['Item']['Photo'][0] ;
							echo $html->link($html->image('photos/home/'.$photo['urlPhoto'], array('width' => 100, 'height' => 150)),
											array('controller' => 'sales', 'action' => 'view', $photo = $follow['Sale']['id']),
											array('escape' => false));
							?>
							</td>
			</tr>
			<tr>
				<td><?php echo $html->link($follow['Sale']['Item']['name'], array('controller' => 'items', 'action' => 'view', $follow['Sale']['Item']['id'])); ?></td>
			</tr>
			<tr>
				<td id='<?php echo $i; ?>' class='countdown'>
				
					<?php 
						if($follow['Sale']['timeEnd'] <= date('Y-m-d H:i:s'))
						{	
							
							echo $follow['Sale']['timeEnd'].'<br>';
							echo 'Lasted: ';
							echo $timediff->timeDiff($follow['Sale']['originalTimeEnd'],$follow['Sale']['timeEnd']);  
							
						} else
						{
							$year = date("Y",strtotime($follow['Sale']['timeEnd'])); 
							$month = date("m",strtotime($follow['Sale']['timeEnd']));
							$day = date("d",strtotime($follow['Sale']['timeEnd']));
							$hour = date("H",strtotime($follow['Sale']['timeEnd']));
							$minutes = date("i",strtotime($follow['Sale']['timeEnd']));
							$seconds = date("s",strtotime($follow['Sale']['timeEnd']));	
							echo  '<script> countdown('.$year.','. $month.','. $day.','. $hour.','. $minutes.','. $seconds.','.$i.')</script>';
						}
						
					?>
				
				</td>
			</tr>
			<tr>
				<td>
				<?php
					echo number_format($follow['Sale']['currentPrice']*$currencyValue,2); 
					echo ' ';
					echo $currencyName;
				?>
			</td>
			</tr>
			<tr class="lastbidder">
				<td><?php echo $follow['Sale']['User']['login']; ?></td>
			</tr>
			<tr>
				<td class = "buttonspan clearfix">
					<?php echo $html->link(__('Unfollow', true), array('action' => 'unfollow', $follow['Sale']['id']), array('class'=>'buttonref')); ?>
				</td>
			</tr>
			<?php
			if($follow['Sale']['timeEnd'] > date('Y-m-d H:i:s'))
			{	?>
			<tr>
			
				<td class = "buttonspan clearfix">
					<?php echo $html->link(__('Licitate', true), array('action' => 'licitate', $follow['Sale']['id'],'index',null), array('class'=>'buttonref')); ?>
				</td>
			</tr>
			<?php } ?>
			
		</table>
	</li> 
	

<?php 		$i++;
		endforeach; ?>
</ul>
</div>
<div class="paging">
	<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
 | 	<?php echo $paginator->numbers();?>
	<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?>
</div>
